package fr.univsavoie.tatiana2dvisualisation;

import java.util.Vector;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.editparts.ScalableRootEditPart;
import org.eclipse.gef.ui.parts.GraphicalEditor;

import fr.emse.tatiana.replayable.IReplayableModel;

public class EyeTrackerDisplayEditor extends GraphicalEditor {

	private DrawCondition defaultdraw;
	private Vector<DrawCondition> conditions = new Vector<DrawCondition>();
	private IReplayableModel model;
	
	public EyeTrackerDisplayEditor(IReplayableModel model) {
		setEditDomain(new DefaultEditDomain(this));
		this.model=model;
		defaultdraw = new DrawCondition(null,ColorConstants.blue,ColorConstants.gray,ColorConstants.red);
		if (model.getFacetCol("type")>=0) {
			DrawCondition eyecond = new DrawCondition("eye",null,null,ColorConstants.red);
			eyecond.setCurrentShape(DrawCondition.DISK);
			DrawCondition pencond = new DrawCondition("pen",ColorConstants.blue,ColorConstants.gray,ColorConstants.red);
			conditions.add(pencond);
			conditions.add(eyecond);
		}
	}

	@Override
	protected void configureGraphicalViewer() {
		super.configureGraphicalViewer();   
        GraphicalViewer viewer = getGraphicalViewer();
        viewer.setEditPartFactory(new EyeTrackerPartFactory(conditions));
        ScalableRootEditPart rootEditPart = new ScalableRootEditPart();
		viewer.setRootEditPart(rootEditPart);
		
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		// TODO Auto-generated method stub
		
	}

	public GraphicalViewer getViewer() {
		return getGraphicalViewer();
	}

	@Override
	protected void initializeGraphicalViewer() {
		GraphicalViewer viewer = getGraphicalViewer();
		viewer.setContents(model);
		//EyeTrackerModelPart part = (ReplayableModelPart)((EyeTrackerPartFactory)viewer.getEditPartFactory()).getEditPart(model);
		//part.setViewPort((Viewport) ((ScalableRootEditPart) viewer.getRootEditPart()).getFigure());
		this.refresh();
	}

	public void refresh() {
		this.refresh(-1000,-1000,-1000);
		
	}

	public void refresh(long start, long end, long currenttime) {
		EyeTrackerModelPart part = (EyeTrackerModelPart)((EyeTrackerPartFactory)getGraphicalViewer().getEditPartFactory()).getEditPart(model);
		part.setCurrentTime(start, end, currenttime);
		
	}

}
